package com.ds.robot.assistant.component;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.extra.pinyin.PinyinUtil;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

class PinyinComparator implements Comparator<String> {
    @Override
    public int compare(String o1, String o2) {
        String pinyin1 = getPinyin(o1);
        String pinyin2 = getPinyin(o2);
        return pinyin1.compareTo(pinyin2);
    }

    private String getPinyin(String chinese) {
        if (CharSequenceUtil.isBlank(chinese)) {
            return "";
        }
        return PinyinUtil.getPinyin(chinese);
    }

    public static void main(String[] args) {
        List<String> chineseList = Arrays.asList("魏韶颖", "张三", "李四", "王五");
        for (String c : chineseList) {
            System.out.println("PinyinUtil.getPinyin(chinese) = " + PinyinUtil.getPinyin(c));
        }
    }
}
